/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-08-03
 * Time: 20:51
 */
class Animal {
    //12
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {

        System.out.println(this.name+"正在吃！");
    }
}

class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    public void bark() {
        System.out.println("在汪汪叫！");
    }
    public void eat() {
        System.out.println(this.name+" 正在吃狗粮!!! ");
    }
}

class  cat extends  Animal {


    public cat(String name, int age) {
        super(name, age);
    }
    public void eat() {
        System.out.println(this.name+"正在吃猫粮！！！");
    }
    public void miaomiao(){
        System.out.println("正在喵喵叫！");
    }
}

public class Test1 {

    public static void  eatfunc(Animal animal) {
        animal.eat();
    }
    public static void main(String[] args) {
        Dog dog = new Dog("niuniu",2);
        cat mao = new cat("fafa",2);
        eatfunc(dog);
        eatfunc(mao);
        System.out.println("================");
        Animal animal = new Dog( "yiyi",3);
        Dog dog1 = (Dog) animal ;
        dog1.bark();
    }
    public static void  func (Animal animal) {

    }
    public static  Animal func1( ) {
        Dog dog = new Dog("huahua",2);
        return dog;
    }
    public static void main1(String[] args) {

        Dog dog = new Dog("niuniu",2);
        //animal的引用指向了dog所指向的引用所指的对象；
        Animal animal = dog;
        //指dog所引用的对象给animal；
        // 这种指向一般要保证等号两边类型一致，因为她两具备父子类之间的关系，所以可以引用；

        Animal animal1 = new Dog("fafa",2);
        Animal animal2 = new cat("huahua",2);
          animal1.eat();//此时调用的是animal的eat





        /*dog.eat();
        dog.bark();
        System.out.println("============");
        */

        /*Animal animal = new Animal("fafa",1);
        animal.eat();
        animal.bark;
        *
        *通过父类引用 不能调用子类，只能调用父类特有的成员变量或成员方法
        */
    }
}
